package com.example.demo.dao;

import com.example.demo.model.Admin;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class AdminDao extends BaseDao {
    public Admin login(Admin admin){
        String sql = "select * from admin where aname=? and password=?";
        Admin adminRst = null;
        try {
            PreparedStatement prst = con.prepareStatement(sql);//把sql语句传给数据库操作对象
            prst.setString(1, admin.getName());
            prst.setString(2, admin.getPassword());
            ResultSet executeQuery = prst.executeQuery();
            if(executeQuery.next()){
                adminRst = new Admin();
                adminRst.setId(executeQuery.getInt("ano"));
                adminRst.setName(executeQuery.getString("aname"));
                adminRst.setPassword(executeQuery.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return adminRst;
    }
}

